package kaluli;
// 文件名 SendEmail.java
 
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
 
public class SendEmail
{
	
	
	public static void main(String[] args) throws MessagingException {
		
		
        Properties props = new Properties();  
        // 开启debug调试  
        props.setProperty("mail.debug", "true");  
        // 发送服务器需要身份验证  
        props.setProperty("mail.smtp.auth", "true");  
        // 设置邮件服务器主机名  
        props.setProperty("mail.host", "smtp.exmail.qq.com");  
        // 发送邮件协议名称  
        props.setProperty("mail.transport.protocol", "smtp");  
          
        // 设置环境信息  
        Session session = Session.getInstance(props);  
          
        // 创建邮件对象  
        Message msg = new MimeMessage(session);  
        msg.setSubject("JavaMail测试");  
        StringBuffer buffer = new StringBuffer();
        buffer.append("有问题订单列表:\r\n");
        buffer.append("订单号:132456798\r\n");
        buffer.append("订单号:132456798\r\n");
        buffer.append("订单号:132456798\r\n");
        buffer.append("订单号:132456798\r\n");
        
        // 设置邮件内容  
        msg.setText(buffer.toString());
        
        // 设置发件人  
        msg.setFrom(new InternetAddress("nsapi@kaluli.com"));  
          
        Transport transport = session.getTransport();  
        String emails="niwei@kaluli.com,zhangyizhi@kaluli.com";
        String[] s =emails.split(",");
        InternetAddress[] address = new InternetAddress[s.length];
        for(int i=0;i<s.length;i++){
        	address[i]=new InternetAddress(s[i]);
        }
        // 连接邮件服务器  (用户名密码)
        transport.connect("nsapi@kaluli.com", "rK1234");  
        // 发送邮件  
        transport.sendMessage(msg, address);
        // 关闭连接  
        transport.close();  
    }  
}